﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindowsFormsApplication5.settings
{
    public class PortConfig
    {
        private String port;
        private Boolean port_enabled;
        private String port_description;
        private String ip;
        private String subnetMask;
        private String clockrate;

        public enum clockrates
        {
            SLOW, NORMAL, FAST, FASTEST
        }
        public enum Ports
        {
           SERIAL0, SERIAL1, FAST_ETHERNET0, FAST_ETHERNET1
        }

        /*
         * Getter und Setter
         */
        public String getPortString(Ports ports)
        {
            switch (ports)
            {
                case Ports.SERIAL0: return "Serial 0/0";
                case Ports.SERIAL1: return "Serial 1/0";
                case Ports.FAST_ETHERNET0: return "FastEthernet 0/0";
                case Ports.FAST_ETHERNET1: return "FastEthernet 0/1";
                default: return "";
            }
        }
        public String getPortStringFromInt(int num)
        {
            switch (num)
            {
                case 0: return "Serial 0/0";
                case 1: return "Serial 1/0";
                case 2: return "FastEthernet 0/0";
                case 3: return "FastEthernet 0/1";
                default: return "";
            }
        }

        public String Port { get; set; }
        public Boolean Port_Enabled { get; set; }
        public String Port_Description { get; set; }
        public String Ip { get; set; }
        public String Clockrate { get; set; }
        public String SubnetMask { get; set; }

        public PortConfig(Ports ports, Boolean port_enabled, String port_description, String ip, String subnetMask, String clockrate)
        {
            Port = getPortString(ports);
            Port_Enabled = port_enabled;
            Port_Description = port_description;
            Ip = ip;
            SubnetMask = subnetMask;
            Clockrate = clockrate;
        }
        public PortConfig(int portnum, Boolean port_enabled, String port_description, String ip, String subnetMask, String clockrate)
        {
            Port = getPortStringFromInt(portnum);
            Port_Enabled = port_enabled;
            Port_Description = port_description;
            Ip = ip;
            SubnetMask = subnetMask;
            Clockrate = clockrate;
        }

        public PortConfig(String port, Boolean port_enabled, String port_description, String ip, String subnetMask, String clockrate)
        {
            Port = port;
            Port_Enabled = port_enabled;
            Port_Description = port_description;
            Ip = ip;
            SubnetMask = subnetMask;
            Clockrate = clockrate;
        }

        /**
         * Baut den Ausgabe-String für die Schnittstellen-Konfiguration zusammen
         * und gibt ihn zurück
         */
        public String toString()
        {
            String ret = "";

            if (Port_Enabled == true)
            {
                ret += "interface " + Port + Environment.NewLine;
                ret += " description " + Port_Description + Environment.NewLine;
                ret += " ip address " + Ip + " " + SubnetMask + Environment.NewLine;
                if (Clockrate != null && Clockrate != "")
                {
                    ret += " clock rate " + Clockrate + Environment.NewLine;
                }
                ret += "!" + Environment.NewLine;
            }
            return ret;
        }
        
    }
}
